﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YunLian.Cache.Internal
{
    public sealed class CacheEventArgs:EventArgs
    {
        public CacheEventArgs(string key, string region, CacheItemRemovedReason reason, object value, int level = 0)
        {
            
            if(string.IsNullOrWhiteSpace(key))throw new ArgumentNullException(nameof(key));
            Reason = reason;
            Key = key;
            Region = region;
            Level = level;
            Value = value;
        }
        public string Key { get; }

        
        public string Region { get; }

        
        public CacheItemRemovedReason Reason { get; }

       
        public int Level { get; }

        
        public object Value { get; }

        public override string ToString()
        {
            return $"CacheItemRemovedEventArgs {Region}:{Key} - {Reason} {Level}";
        }
    }
    public sealed class CacheItemRemovedEventArgs : EventArgs
    {
        
        public CacheItemRemovedEventArgs(string key, string region, CacheItemRemovedReason reason, object value, int level = 0)
        {
            if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key));

            Reason = reason;
            Key = key;
            Region = region;
            Level = level;
            Value = value;
        }

        
        public string Key { get; }

        
        public string Region { get; }

        
        public CacheItemRemovedReason Reason { get; }

        
        public int Level { get; }

        
        public object Value { get; }

        
        public override string ToString()
        {
            return $"CacheItemRemovedEventArgs {Region}:{Key} - {Reason} {Level}";
        }
    }
    public sealed class CacheActionEventArgs : EventArgs
    {
        
        public CacheActionEventArgs(string key, string region)
        {
            if (string.IsNullOrWhiteSpace(key)) throw new ArgumentNullException(nameof(key));

            Key = key;
            Region = region;
        }

        
        public CacheActionEventArgs(string key, string region, CacheActionEventArgOrigin origin)
            : this(key, region)
        {
            Origin = origin;
        }

        
        public string Key { get; }

        
        public string Region { get; }

        
        public CacheActionEventArgOrigin Origin { get; } = CacheActionEventArgOrigin.Local;

        
        public override string ToString()
        {
            return $"CacheActionEventArgs {Region}:{Key} - {Origin}";
        }
    }

    
    public sealed class CacheClearEventArgs : EventArgs
    {
       
        public CacheClearEventArgs(CacheActionEventArgOrigin origin = CacheActionEventArgOrigin.Local)
        {
            Origin = origin;
        }

        
        public CacheActionEventArgOrigin Origin { get; }

        
        public override string ToString()
        {
            return $"CacheClearEventArgs {Origin}";
        }
    }

    
    public sealed class CacheClearRegionEventArgs : EventArgs
    {
        
        public CacheClearRegionEventArgs(string region, CacheActionEventArgOrigin origin = CacheActionEventArgOrigin.Local)
        {
            if(string.IsNullOrWhiteSpace(region))throw new ArgumentNullException(nameof(region));

            Region = region;
            Origin = origin;
        }

        
        public string Region { get; }

        
        public CacheActionEventArgOrigin Origin { get; }

        
        public override string ToString()
        {
            return $"CacheClearRegionEventArgs {Region} - {Origin}";
        }
    }
}
